/**
 * 管理后台路由配置
 * @module router/admin
 */

import { authService } from '../services';

// 路由守卫 - 检查是否已登录
const requireAuth = (to, from, next) => {
  if (authService.isLoggedIn()) {
    next();
  } else {
    next({ name: 'admin-login', query: { redirect: to.fullPath } });
  }
};

const adminRoutes = [
  {
    path: '/admin',
    name: 'admin',
    component: () => import('../views/admin/AdminLayout.vue'),
    redirect: { name: 'admin-dashboard' },
    beforeEnter: requireAuth,
    children: [
      {
        path: '',
        redirect: '/admin/dashboard'
      },
      {
        path: 'dashboard',
        name: 'admin-dashboard',
        component: () => import('../views/admin/Dashboard.vue'),
        meta: { title: '仪表盘' }
      },
      // 文章管理
      {
        path: 'articles',
        name: 'admin-articles',
        component: () => import('../views/admin/articles/ArticleList.vue'),
        meta: { title: '文章管理' }
      },
      {
        path: 'articles/create',
        name: 'admin-articles-create',
        component: () => import('../views/admin/articles/ArticleEdit.vue'),
        meta: { title: '创建文章' }
      },
      {
        path: 'articles/edit/:id',
        name: 'admin-articles-edit',
        component: () => import('../views/admin/articles/ArticleEdit.vue'),
        meta: { title: '编辑文章' },
        props: true
      },
      // 分类管理
      {
        path: 'categories',
        name: 'admin-categories',
        component: () => import('../views/admin/categories/CategoryList.vue'),
        meta: { title: '分类管理' }
      },
      // 评论管理
      {
        path: 'comments',
        name: 'admin-comments',
        component: () => import('../views/admin/comments/CommentList.vue'),
        meta: { title: '评论管理' }
      },
      // 消息管理
      {
        path: 'messages',
        name: 'admin-messages',
        component: () => import('../views/admin/messages/MessageList.vue'),
        meta: { title: '联系消息' }
      },
      // 媒体管理 - 新增
      {
        path: 'media',
        name: 'admin-media',
        component: () => import('../views/admin/media/MediaManager.vue'),
        meta: { title: '媒体管理' }
      },
      // 项目管理 - 新增
      {
        path: 'projects',
        name: 'admin-projects',
        component: () => import('../views/admin/projects/ProjectList.vue'),
        meta: { title: '项目管理' }
      },
      // 网站设置 - 新增
      {
        path: 'settings',
        name: 'admin-settings',
        component: () => import('../views/admin/settings/SiteSettings.vue'),
        meta: { title: '网站设置' }
      },
      // 账户设置
      {
        path: 'account',
        name: 'admin-account',
        component: () => import('../views/admin/Account.vue'),
        meta: { title: '账户设置' }
      }
    ]
  },
  // 登录页
  {
    path: '/admin/login',
    name: 'admin-login',
    component: () => import('../views/admin/Login.vue'),
    meta: { title: '管理员登录' }
  }
];

export default adminRoutes; 